package com.zhouyibike.uu.ui.activity.web;

import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.TextView;

import com.zhouyibike.uu.R;
import com.zhouyibike.uu.config.Config;
import com.zhouyibike.uu.entity.ZhinanResult;
import com.zhouyibike.uu.http.ApiCallback;
import com.zhouyibike.uu.ui.adapter.ZhinanAdapter;
import com.zhouyibike.uu.ui.base.BaseActivity;

import java.util.HashMap;
import java.util.Map;

public class ZhiNanActivity extends BaseActivity implements View.OnClickListener{
    private ListView tv_xieyi;
    private ImageButton mBtnBack;
    private TextView mBtnTitle;
    private ZhinanAdapter zhinanAdapter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhi_nan);
        initView();
        getWZMsg();

    }
    private void initView() {
        mBtnBack = (ImageButton) findViewById(R.id.bar_btn_back);
        mBtnTitle = (TextView) findViewById(R.id.bar_text_title);
        mBtnTitle.setText("使用指南");
        mBtnBack.setOnClickListener(this);
        tv_xieyi= (ListView) findViewById(R.id.tv_zhinan_msg);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bar_btn_back:
                finish();
                break;
        }
    }
    private void getWZMsg(){
        Map<String, String> params = new HashMap<>();
        params.put("token", preferences.getString("token",""));
        params.put("type", "2");
        showProgressDialog();
        addSubscription(apiStores.GetInformationzn(params),
                new ApiCallback<ZhinanResult>() {

                    @Override
                    public void onSuccess(ZhinanResult model) {
                        if(model.getStatus()== Config.SUCCESSCODE){
                            initList(model);
                        }else{
                            toastShow(model.getMessage());
                        }
                    }

                    @Override
                    public void onFailure(String msg) {
                        toastShow(msg);
                    }

                    @Override
                    public void onFinish() {
                        dismissProgressDialog();
                    }
                });
    }
    private void initList(ZhinanResult model){
        zhinanAdapter=new ZhinanAdapter(this,model.getData());
        tv_xieyi.setAdapter(zhinanAdapter);
//        tv_xieyi.setOnItemClickListener(new AdapterView.OnItemClickListener() {
//            @Override
//            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//
//            }
//        });
    }
}
